#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e6 + 5;

ll n, p, k;
ll a[N];
ll prod[N];
ll f[N];
ll gcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
ll inv(ll a) {
  ll x, y;
  gcd(a, p, x, y);
  x %= p;
  if (x < 0) x += p;
  return x;
}
template <class T>
T read(T& x) {
  x = 0;
  char ch = 0;
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read(n), read(p), read(k);
  rep(i, 1, n) read(a[i]);
  prod[0] = 1;
  rep(i, 1, n) prod[i] = prod[i - 1] * a[i] % p;
  ll c = inv(prod[n]);
  per(i, n, 1) {
    f[i] = c * prod[i - 1] % p;
    c = c * a[i] % p;
  }
  ll ans = 0;
  ll x = 1;
  rep(i, 1, n) {
    x = x * k % p;
    ans = (ans + x * f[i] % p) % p;
  }
  cout << ans;
  return 0;
}